package com.lcl.jarvis.admin.modules.person.service.impl;

import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import com.lcl.jarvis.common.model.PageResult;
import com.lcl.jarvis.admin.modules.person.dto.request.TbEpidemiologicalInfoReqDTO;
import com.lcl.jarvis.admin.modules.person.dto.response.TbEpidemiologicalInfoRespDTO;
import com.lcl.jarvis.admin.modules.person.dto.request.TbEpidemiologicalInfoPageReqDTO;

import com.lcl.jarvis.admin.modules.person.mapper.TbEpidemiologicalInfoMapper;
import com.lcl.jarvis.admin.modules.person.entity.TbEpidemiologicalInfo;
import com.lcl.jarvis.admin.modules.person.service.ITbEpidemiologicalInfoService;
import lombok.RequiredArgsConstructor;

/**
 * 数据筛查管理Service业务层处理
 *
 * @author licl
 * @date 2024-06-21 16:32:16
 */
@Service
@RequiredArgsConstructor
public class TbEpidemiologicalInfoServiceImpl extends ServiceImpl<TbEpidemiologicalInfoMapper, TbEpidemiologicalInfo> implements ITbEpidemiologicalInfoService {

    /**
     * 新增数据筛查管理
     *
     * @param body 数据筛查管理
     * @return 结果
     */
    @Override
    public Integer add(TbEpidemiologicalInfoReqDTO body) {
        TbEpidemiologicalInfo entity = BeanUtil.copyProperties(body, TbEpidemiologicalInfo.class);
        return baseMapper.insert(entity);
    }

    /**
     * 批量删除数据筛查管理
     *
     * @param ids 需要删除的数据筛查管理主键
     * @return 结果
     */
    @Override
    public Integer remove(List<String> ids) {
        return baseMapper.deleteByIds(ids);
    }

    /**
     * 修改数据筛查管理
     *
     * @param body 数据筛查管理
     * @return 结果
     */
    @Override
    public Integer update(TbEpidemiologicalInfoReqDTO body) {
        TbEpidemiologicalInfo entity = BeanUtil.copyProperties(body, TbEpidemiologicalInfo.class);

        return baseMapper.updateById(entity);
    }


    /**
     * 查询数据筛查管理
     *
     * @param id 数据筛查管理主键
     * @return 数据筛查管理
     */
    @Override
    public TbEpidemiologicalInfoRespDTO detail(String id) {
        TbEpidemiologicalInfo entity = baseMapper.selectById(id);
        return BeanUtil.copyProperties(entity, TbEpidemiologicalInfoRespDTO.class);
    }

    /**
     * 查询数据筛查管理列表
     *
     * @param req
     * @return 数据筛查管理
     */
    @Override
    public PageResult<TbEpidemiologicalInfoRespDTO> page(TbEpidemiologicalInfoPageReqDTO req) {
        LambdaQueryWrapper<TbEpidemiologicalInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StrUtil.isNotBlank(req.getQueryId()), TbEpidemiologicalInfo::getQueryId, req.getQueryId());
        queryWrapper.eq(StrUtil.isNotBlank(req.getPersonId()), TbEpidemiologicalInfo::getPersonId, req.getPersonId());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getMenarcheAge()), TbEpidemiologicalInfo::getMenarcheAge, req.getMenarcheAge());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getCycle()), TbEpidemiologicalInfo::getCycle, req.getCycle());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getMenstrualPeriod()), TbEpidemiologicalInfo::getMenstrualPeriod, req.getMenstrualPeriod());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsDysmenorrhea()), TbEpidemiologicalInfo::getIsDysmenorrhea, req.getIsDysmenorrhea());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsMenopause()), TbEpidemiologicalInfo::getIsMenopause, req.getIsMenopause());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getMenopauseAge()), TbEpidemiologicalInfo::getMenopauseAge, req.getMenopauseAge());
        queryWrapper.eq(StrUtil.isNotBlank(req.getHasPregnancy()), TbEpidemiologicalInfo::getHasPregnancy, req.getHasPregnancy());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getFirstPregnancyAge()), TbEpidemiologicalInfo::getFirstPregnancyAge, req.getFirstPregnancyAge());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getPregnancyCount()), TbEpidemiologicalInfo::getPregnancyCount, req.getPregnancyCount());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getAbortionCount()), TbEpidemiologicalInfo::getAbortionCount, req.getAbortionCount());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getTotalPregnancyTime()), TbEpidemiologicalInfo::getTotalPregnancyTime, req.getTotalPregnancyTime());
        queryWrapper.eq(StrUtil.isNotBlank(req.getHasGivenBirth()), TbEpidemiologicalInfo::getHasGivenBirth, req.getHasGivenBirth());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getFirstBirthAge()), TbEpidemiologicalInfo::getFirstBirthAge, req.getFirstBirthAge());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getBirthCount()), TbEpidemiologicalInfo::getBirthCount, req.getBirthCount());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getFullTermPregnancyCount()), TbEpidemiologicalInfo::getFullTermPregnancyCount, req.getFullTermPregnancyCount());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getFirstBornPregnancyAge()), TbEpidemiologicalInfo::getFirstBornPregnancyAge, req.getFirstBornPregnancyAge());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsBreastfeeding()), TbEpidemiologicalInfo::getIsBreastfeeding, req.getIsBreastfeeding());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getBreastfeedingStartAge()), TbEpidemiologicalInfo::getBreastfeedingStartAge, req.getBreastfeedingStartAge());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getBreastfeedingLongestTime()), TbEpidemiologicalInfo::getBreastfeedingLongestTime, req.getBreastfeedingLongestTime());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getTotalBreastfeedingTime()), TbEpidemiologicalInfo::getTotalBreastfeedingTime, req.getTotalBreastfeedingTime());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsDrinking()), TbEpidemiologicalInfo::getIsDrinking, req.getIsDrinking());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getDrinkingStartAge()), TbEpidemiologicalInfo::getDrinkingStartAge, req.getDrinkingStartAge());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getDrinkingYears()), TbEpidemiologicalInfo::getDrinkingYears, req.getDrinkingYears());
        queryWrapper.eq(StrUtil.isNotBlank(req.getDrinkingFrequency()), TbEpidemiologicalInfo::getDrinkingFrequency, req.getDrinkingFrequency());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getAlcoholConsumption()), TbEpidemiologicalInfo::getAlcoholConsumption, req.getAlcoholConsumption());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsSmoking()), TbEpidemiologicalInfo::getIsSmoking, req.getIsSmoking());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getSmokingStartAge()), TbEpidemiologicalInfo::getSmokingStartAge, req.getSmokingStartAge());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getSmokingYears()), TbEpidemiologicalInfo::getSmokingYears, req.getSmokingYears());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getSmokingAmount()), TbEpidemiologicalInfo::getSmokingAmount, req.getSmokingAmount());
        queryWrapper.eq(StrUtil.isNotBlank(req.getBreastBenignHistory()), TbEpidemiologicalInfo::getBreastBenignHistory, req.getBreastBenignHistory());
        queryWrapper.eq(StrUtil.isNotBlank(req.getHormoneReplacementTherapy()), TbEpidemiologicalInfo::getHormoneReplacementTherapy, req.getHormoneReplacementTherapy());
        queryWrapper.eq(StrUtil.isNotBlank(req.getFamilyHistory()), TbEpidemiologicalInfo::getFamilyHistory, req.getFamilyHistory());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsDiabetesHistory()), TbEpidemiologicalInfo::getIsDiabetesHistory, req.getIsDiabetesHistory());
        queryWrapper.eq(StrUtil.isNotBlank(req.getDiabetesYears()), TbEpidemiologicalInfo::getDiabetesYears, req.getDiabetesYears());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsDiabetesMedication()), TbEpidemiologicalInfo::getIsDiabetesMedication, req.getIsDiabetesMedication());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsBilateralPalpationAbnormal()), TbEpidemiologicalInfo::getIsBilateralPalpationAbnormal, req.getIsBilateralPalpationAbnormal());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsBilateralSymmetry()), TbEpidemiologicalInfo::getIsBilateralSymmetry, req.getIsBilateralSymmetry());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsBilateralSizeSymmetry()), TbEpidemiologicalInfo::getIsBilateralSizeSymmetry, req.getIsBilateralSizeSymmetry());
        queryWrapper.eq(StrUtil.isNotBlank(req.getBreastDevelopment()), TbEpidemiologicalInfo::getBreastDevelopment, req.getBreastDevelopment());
        queryWrapper.eq(StrUtil.isNotBlank(req.getSuperficialVaricoseVeins()), TbEpidemiologicalInfo::getSuperficialVaricoseVeins, req.getSuperficialVaricoseVeins());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsNippleRetraction()), TbEpidemiologicalInfo::getIsNippleRetraction, req.getIsNippleRetraction());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRednessSwelling()), TbEpidemiologicalInfo::getRednessSwelling, req.getRednessSwelling());
        queryWrapper.eq(StrUtil.isNotBlank(req.getDimpleSign()), TbEpidemiologicalInfo::getDimpleSign, req.getDimpleSign());
        queryWrapper.eq(StrUtil.isNotBlank(req.getOrangePeelSign()), TbEpidemiologicalInfo::getOrangePeelSign, req.getOrangePeelSign());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsLeftPalpationAbnormal()), TbEpidemiologicalInfo::getIsLeftPalpationAbnormal, req.getIsLeftPalpationAbnormal());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getLeftPalpableMassCount()), TbEpidemiologicalInfo::getLeftPalpableMassCount, req.getLeftPalpableMassCount());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftLargestMassAreaLeft()), TbEpidemiologicalInfo::getLeftLargestMassAreaLeft, req.getLeftLargestMassAreaLeft());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftLargestMassAreaRight()), TbEpidemiologicalInfo::getLeftLargestMassAreaRight, req.getLeftLargestMassAreaRight());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftLocation()), TbEpidemiologicalInfo::getLeftLocation, req.getLeftLocation());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftQuadrant()), TbEpidemiologicalInfo::getLeftQuadrant, req.getLeftQuadrant());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftTexture()), TbEpidemiologicalInfo::getLeftTexture, req.getLeftTexture());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftBorder()), TbEpidemiologicalInfo::getLeftBorder, req.getLeftBorder());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftMobility()), TbEpidemiologicalInfo::getLeftMobility, req.getLeftMobility());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftTenderness()), TbEpidemiologicalInfo::getLeftTenderness, req.getLeftTenderness());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftNippleDischarge()), TbEpidemiologicalInfo::getLeftNippleDischarge, req.getLeftNippleDischarge());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftAxillaryLymphNodes()), TbEpidemiologicalInfo::getLeftAxillaryLymphNodes, req.getLeftAxillaryLymphNodes());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftLocalizedThickening()), TbEpidemiologicalInfo::getLeftLocalizedThickening, req.getLeftLocalizedThickening());
        queryWrapper.eq(StrUtil.isNotBlank(req.getIsRightPalpationAbnormal()), TbEpidemiologicalInfo::getIsRightPalpationAbnormal, req.getIsRightPalpationAbnormal());
        queryWrapper.eq(ObjectUtil.isNotNull(req.getRightPalpableMassCount()), TbEpidemiologicalInfo::getRightPalpableMassCount, req.getRightPalpableMassCount());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightLargestMassAreaLeft()), TbEpidemiologicalInfo::getRightLargestMassAreaLeft, req.getRightLargestMassAreaLeft());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightLargestMassAreaRight()), TbEpidemiologicalInfo::getRightLargestMassAreaRight, req.getRightLargestMassAreaRight());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightLocation()), TbEpidemiologicalInfo::getRightLocation, req.getRightLocation());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightQuadrant()), TbEpidemiologicalInfo::getRightQuadrant, req.getRightQuadrant());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightTexture()), TbEpidemiologicalInfo::getRightTexture, req.getRightTexture());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightBorder()), TbEpidemiologicalInfo::getRightBorder, req.getRightBorder());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightMobility()), TbEpidemiologicalInfo::getRightMobility, req.getRightMobility());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightTenderness()), TbEpidemiologicalInfo::getRightTenderness, req.getRightTenderness());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightNippleDischarge()), TbEpidemiologicalInfo::getRightNippleDischarge, req.getRightNippleDischarge());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightAxillaryLymphNodes()), TbEpidemiologicalInfo::getRightAxillaryLymphNodes, req.getRightAxillaryLymphNodes());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightLocalizedThickening()), TbEpidemiologicalInfo::getRightLocalizedThickening, req.getRightLocalizedThickening());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftUltrasonicFinding()), TbEpidemiologicalInfo::getLeftUltrasonicFinding, req.getLeftUltrasonicFinding());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftCyst()), TbEpidemiologicalInfo::getLeftCyst, req.getLeftCyst());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftSolidMass()), TbEpidemiologicalInfo::getLeftSolidMass, req.getLeftSolidMass());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightUltrasonicFinding()), TbEpidemiologicalInfo::getRightUltrasonicFinding, req.getRightUltrasonicFinding());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightCyst()), TbEpidemiologicalInfo::getRightCyst, req.getRightCyst());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightSolidMass()), TbEpidemiologicalInfo::getRightSolidMass, req.getRightSolidMass());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftLocatedAt()), TbEpidemiologicalInfo::getLeftLocatedAt, req.getLeftLocatedAt());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftDistanceToNipple()), TbEpidemiologicalInfo::getLeftDistanceToNipple, req.getLeftDistanceToNipple());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftSizeEstimate1()), TbEpidemiologicalInfo::getLeftSizeEstimate1, req.getLeftSizeEstimate1());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftSizeEstimate2()), TbEpidemiologicalInfo::getLeftSizeEstimate2, req.getLeftSizeEstimate2());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftShape()), TbEpidemiologicalInfo::getLeftShape, req.getLeftShape());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftMargin()), TbEpidemiologicalInfo::getLeftMargin, req.getLeftMargin());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftEchogenicity()), TbEpidemiologicalInfo::getLeftEchogenicity, req.getLeftEchogenicity());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftPosteriorAcousticFeatures()), TbEpidemiologicalInfo::getLeftPosteriorAcousticFeatures, req.getLeftPosteriorAcousticFeatures());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftAspectRatio()), TbEpidemiologicalInfo::getLeftAspectRatio, req.getLeftAspectRatio());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftCalcification()), TbEpidemiologicalInfo::getLeftCalcification, req.getLeftCalcification());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftCalcificationType()), TbEpidemiologicalInfo::getLeftCalcificationType, req.getLeftCalcificationType());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftBloodFlowSignal()), TbEpidemiologicalInfo::getLeftBloodFlowSignal, req.getLeftBloodFlowSignal());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftLymphNode()), TbEpidemiologicalInfo::getLeftLymphNode, req.getLeftLymphNode());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftBreastUltrasoundLevel()), TbEpidemiologicalInfo::getLeftBreastUltrasoundLevel, req.getLeftBreastUltrasoundLevel());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightLocatedAt()), TbEpidemiologicalInfo::getRightLocatedAt, req.getRightLocatedAt());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightDistanceToNipple()), TbEpidemiologicalInfo::getRightDistanceToNipple, req.getRightDistanceToNipple());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightSizeEstimate1()), TbEpidemiologicalInfo::getRightSizeEstimate1, req.getRightSizeEstimate1());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightSizeEstimate2()), TbEpidemiologicalInfo::getRightSizeEstimate2, req.getRightSizeEstimate2());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightShape()), TbEpidemiologicalInfo::getRightShape, req.getRightShape());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightMargin()), TbEpidemiologicalInfo::getRightMargin, req.getRightMargin());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightEchogenicity()), TbEpidemiologicalInfo::getRightEchogenicity, req.getRightEchogenicity());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightPosteriorAcousticFeatures()), TbEpidemiologicalInfo::getRightPosteriorAcousticFeatures, req.getRightPosteriorAcousticFeatures());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightAspectRatio()), TbEpidemiologicalInfo::getRightAspectRatio, req.getRightAspectRatio());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightCalcification()), TbEpidemiologicalInfo::getRightCalcification, req.getRightCalcification());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightCalcificationType()), TbEpidemiologicalInfo::getRightCalcificationType, req.getRightCalcificationType());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightBloodFlowSignal()), TbEpidemiologicalInfo::getRightBloodFlowSignal, req.getRightBloodFlowSignal());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightLymphNode()), TbEpidemiologicalInfo::getRightLymphNode, req.getRightLymphNode());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightBreastUltrasoundLevel()), TbEpidemiologicalInfo::getRightBreastUltrasoundLevel, req.getRightBreastUltrasoundLevel());
        queryWrapper.eq(StrUtil.isNotBlank(req.getLeftLimit()), TbEpidemiologicalInfo::getLeftLimit, req.getLeftLimit());
        queryWrapper.eq(StrUtil.isNotBlank(req.getRightLimit()), TbEpidemiologicalInfo::getRightLimit, req.getRightLimit());
        Page<TbEpidemiologicalInfo> page = baseMapper.selectPage(req.buildPage(), queryWrapper);
        return PageResult.of(page, TbEpidemiologicalInfoRespDTO.class);
    }

    @Override
    public TbEpidemiologicalInfo selectByPersonId(String personId) {
        LambdaQueryWrapper<TbEpidemiologicalInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StrUtil.isNotBlank(personId), TbEpidemiologicalInfo::getPersonId, personId);
        TbEpidemiologicalInfo epidemiologicalInfo = baseMapper.selectOne(queryWrapper);
        return epidemiologicalInfo;
    }

}
